<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AdsConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AdsConfigController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AdsConfig(), function (Grid $grid) {
            //$grid->column('id')->sortable();
            $grid->column('click');
            $grid->column('amount')->display(function ($var) {
                return $var / 100;
            });
            $grid->column('status')->switch();
            $grid->column('default')->switch();
            $grid->column('sort');


            $grid->showQuickEditButton();
            $grid->disableViewButton();
            $grid->disableDeleteButton();
            $grid->disableRowSelector();

        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AdsConfig(), function (Form $form) {
            $form->display('id');
            $form->text('click');
            $form->model()->amount = $form->model()->amount / 100;
            $form->text('amount')->saving(function ($var) {
                $var = $var * 100;
                return $var;
            });
            $form->switch('status')->default(1);
            $form->switch('default')->default(0);
            $form->text('sort')->default(0);
            $form->image('icon')->uniqueName()->required();
        });
    }
}
